<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p id="app">
        123
    </p>
    <script>
        var p = document.getElementById("app");
        var flag = 0;
        p.onclick = function () {
            if (flag == 0) {
                p.style.backgroundColor = "red";
                flag++;
            } else if (flag == 1) {
                p.style.backgroundColor = "blue";
                flag--
            };

        }
    </script>
</body>

</html>